package com.linux.huhx.base;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by huhx on 2017-05-15.
 */
public abstract class BaseController implements Controller {
    @Override
    @SuppressWarnings({"unchecked","rawtypes"})
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map map = this.handleInner(request, response);

        Map result = new HashMap();
        result.put("Json", map);
//        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(null);
        return new ModelAndView("jsonView", result);
    }

    protected abstract Map handleInner(HttpServletRequest request, HttpServletResponse response) throws Exception;
}
